<script>
	import Vue from 'vue'
	export default {
		onLaunch: function() {
			// colorUI配置
			 uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})
			// 免登陆配置
			let hansLogin = uni.getStorageSync('uerInfo')
			if (hansLogin.access_token) {
				uni.navigateTo({
					url: '/pages/map/index'
				})
			}
			// #ifdef APP-PLUS
			//开启推送
			uni.subscribePush({
				provider: "unipush",
				success: function(res) {
					console.log("success:" + JSON.stringify(res)); // 包含CID在内的信息
					uni.setStorage({ // 登录app，将用户信息保存在本地
						key: 'clientid',  
						data: res.clientid  
					})
				}
			});
			let osname = plus.os.name
			console.log(osname)
			if (osname == 'Android') {
				uni.onPush({
					provider: "unipush",
					success: function() {
						console.log("监听透传成功");
					},
					callback: function(data) {
						console.log("接收到透传数据：" + JSON.stringify(data));
						plus.push.createMessage(data.data, {});
					}
				});
			}
			// 监听在线消息事件
			if (osname == 'iOS') {
				plus.push.addEventListener('receive', function(msg) {
					plus.push.createMessage(msg.content, "LocalMSG", {
						cover: false
					});
					setTimeout(() => {
						plus.push.clear();
					}, 3000)
				}, false);
			}
			plus.push.addEventListener(
				"click",
			   // 点击消息栏推送消息，执行函数
				function(data) {
					console.log(data, '业务逻辑');
				},
				false
			);
			plus.push.addEventListener('receive',function(res){
				let options = {cover:false};
				console.log(res)
				console.log(res.content)
				plus.push.createMessage(res.content,res.payload,options);
			}, false)
			// #endif
		},
		onShow: function() { // app展示调用
			console.log('App Show')
		},
		onHide: function() { // app隐藏调用
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	/* #ifndef APP-PLUS-NVUE */
		@import "colorui/main.css";
		@import "colorui/icon.css";
		@import "common/app.css";
		@import "common/icon-font/iconfont.css";
	/* #endif */
</style>
